﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Dcms.BLL;
using Dcms.Model;

public partial class Manage_Modle_ModelField_AjaxPost : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string type = Request.Form["type"] + "";
        switch (type)
        {
            case "getFieldInfo":
                //取得对应字段中控件的内容
                getFieldInfo();
                break;
            case "setFieldInfo":
                //设置对应字段中控件的内容
                setFieldInfo();
                break;
            case "getFieldHelpInfo":
                //取得对应字段的帮助信息
                getFieldHelpInfo();
                break;
            case "setFieldHelpInfo":
                //设置对应字段的帮助信息
                setFieldHelpInfo();
                break;
            default:
                WriteInfo("-1");
                break;
        }
    }

    /// <summary>
    /// 取得对应字段中控件的内容
    /// </summary>
    private void getFieldInfo()
    {
        string strRefInfo = "-1";
        string strFieldID = Request.Form["fieldid"] + "";
        int intFieldID = 0;
        int.TryParse(strFieldID, out intFieldID);
        Dcms_ModelFieldBLL bllModelField = new Dcms_ModelFieldBLL();
        Dcms_ModelFieldModel mModelField = bllModelField.GetModelByID(intFieldID);
        if (mModelField != null)
        {
            strRefInfo = mModelField.mf_FieldInfo;
        }
        WriteInfo(strRefInfo);
    }

    /// <summary>
    /// 设置对应字段中控件的内容
    /// </summary>
    private void setFieldInfo()
    {
        string strRefInfo = "0";
        string strFieldID = Request.Form["fieldid"] + "";
        string strFieldInfo = Request.Form["fieldinfo"] + "";
        int intFieldID = 0;
        int.TryParse(strFieldID, out intFieldID);
        Dcms_ModelFieldBLL bllModelField = new Dcms_ModelFieldBLL();
        Dcms_ModelFieldModel mModelField = bllModelField.GetModelByID(intFieldID);
        try
        {
            mModelField.mf_FieldInfo = strFieldInfo;
            bllModelField.Update(mModelField);
            strRefInfo = "1";
        }
        catch
        {}
        WriteInfo(strRefInfo);
    }

    /// <summary>
    /// 取得对应字段的帮助信息
    /// </summary>
    private void getFieldHelpInfo()
    {
        string strRefInfo = "-1";
        string strFieldID = Request.Form["fieldid"] + "";
        int intFieldID = 0;
        int.TryParse(strFieldID, out intFieldID);
        Dcms_ModelFieldBLL bllModelField = new Dcms_ModelFieldBLL();
        Dcms_ModelFieldModel mModelField = bllModelField.GetModelByID(intFieldID);
        if (mModelField != null)
        {
            strRefInfo = mModelField.mf_FieldHelpInfo;
        }
        WriteInfo(strRefInfo);
    }

    /// <summary>
    /// 设置对应字段的帮助信息
    /// </summary>
    private void setFieldHelpInfo()
    {
        string strRefInfo = "0";
        string strFieldID = Request.Form["fieldid"] + "";
        string strFieldInfo = Request.Form["fieldinfo"] + "";
        int intFieldID = 0;
        int.TryParse(strFieldID, out intFieldID);
        Dcms_ModelFieldBLL bllModelField = new Dcms_ModelFieldBLL();
        Dcms_ModelFieldModel mModelField = bllModelField.GetModelByID(intFieldID);
        try
        {
            mModelField.mf_FieldHelpInfo = strFieldInfo;
            bllModelField.Update(mModelField);
            strRefInfo = "1";
        }
        catch
        { }
        WriteInfo(strRefInfo);
    }

    /// <summary>
    /// 将内容输出到页面上
    /// </summary>
    /// <param name="strInfo"></param>
    private void WriteInfo(string strInfo)
    {
        Response.Clear();
        Response.ContentEncoding = Encoding.UTF8;
        Response.Write(strInfo);
        Response.End();
    }
}
